package com.sntk.organauthomanager.infrastructure.convert;

import com.sntk.organauthomanager.domain.model.User;
import com.sntk.organauthomanager.domain.model.UserType;
import com.sntk.organauthomanager.infrastructure.db.entity.UserEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * @ClassName: UserConvert
 * @author: wgchao
 * @createTime: 2020/7/21 8:42 AM
 * @Description: TODO
 */
@Component
public class UserConvert {
    public UserEntity convert(User user){
        UserEntity userEntity = new UserEntity();
        BeanUtils.copyProperties(user, userEntity);
        userEntity.setUserType(user.getUserType().getIndex());
        return userEntity;
    }

    public User convert(UserEntity userEntity){
        return new User(userEntity.getId(), userEntity.getUname(), userEntity.getInstitutionNumber(), userEntity.getPassword(),
                userEntity.getUserName(), userEntity.getHisCode(), userEntity.getHisDepartmentCode(), userEntity.getShorthandCode(),
                userEntity.getPhoneNumber(), userEntity.getRemark(), UserType.get(userEntity.getUserType()),
                userEntity.getDisabled(), userEntity.getVersion());
    }
}
